﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(Button))]
public class UIButtonSound : MonoBehaviour, IEventSystemHandler, IPointerClickHandler, IPointerEnterHandler
{
    private Button button;
    private static Effect clickEffect;
    private static Effect selectEffect;

    [RuntimeInitializeOnLoadMethod]
    private static void Init()
    {
        clickEffect = GameResources.Effects.ButtonClick;
        selectEffect = GameResources.Effects.ButtonSelect;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (clickEffect != null)
        {
            clickEffect.Spawn<Effect>();
        }
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (selectEffect != null)
        {
            selectEffect.Spawn<Effect>();
        }
    }
}

